package com.attrisoft.sanger.wrapper;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;

public class Main {
    
    public static void main(String[] argv) throws Exception {
        
        Matrix matrix = new Matrix();
        File[] files = new File("data").listFiles();
        for (File file : files) {
            String from = file.getName();
            BufferedReader reader = new BufferedReader(new FileReader(file));
            for (String line; (line = reader.readLine()) != null;) {
                String to = line.substring(0, line.indexOf('\t'));
                String val = line.substring(line.indexOf('\t')).trim();
                int num;
                int index = val.indexOf('e');
                if (index < 0) {
                    num = 0;
                } else {
                    num = Integer.parseInt(val.substring(index+2));
                }
                matrix.put(from.trim(), to.trim(), num);
            }
        }
        
        matrix = matrix.getWeighted();
        PrintStream out = new PrintStream(new FileOutputStream("output/weighted.csv"));
        matrix.toCsv(out);
        out.close();
        
        matrix = matrix.getMarkov();
        out = new PrintStream(new FileOutputStream("output/markov.csv"));
        matrix.toCsv(out);
        out.close();
        
        out = new PrintStream(new FileOutputStream("out/data.abc"));
        matrix.toAbc(out);
        out.close();
        
        out = new PrintStream(new FileOutputStream("out/data.ridx"));
        matrix.toRowIndex(out);
        out.close();
    }
}
